package com.ruoyi.device.controller;


import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.device.domain.DeviceType;
import com.ruoyi.device.service.IDeviceInfoService;
import com.ruoyi.device.service.IDeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Anonymous
@RequestMapping("/device/deviceType")
//@Anonymous
public class DeviceTypeController  extends BaseController {
    @Autowired
    private IDeviceTypeService deviceTypeService ;
    private IDeviceInfoService deviceInfoService;
    /**
     * 查询设备分类列表
     */
    @GetMapping("/getList")
    public AjaxResult getList()
    {
        return success(deviceTypeService.selectDeviceTypeList(new DeviceType()));
    }

    /**
     * 查询设备
     * @param deviceType
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(DeviceType deviceType)
    {
        startPage();
        List<DeviceType> list = deviceTypeService.selectDeviceTypeList(deviceType);
        return getDataTable(list);
    }
    /**
     * 新增设备查询
     */
    @PostMapping
    public AjaxResult add(@RequestBody DeviceType deviceType)
    {
        deviceType.setCreateTime(DateUtils.getNowDate());
        return toAjax(deviceTypeService.insertDeviceTypeTable(deviceType));
    }
    /**
     * 修改设备查询
     */
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceType deviceType)
    {
        deviceType.setUpdateTime(DateUtils.getNowDate());
        return toAjax(deviceTypeService.updateDeviceTypeTable(deviceType));
    }

    /**
     * 删除设备查询
     */
    @DeleteMapping("/{typeId}")
    public AjaxResult remove(@PathVariable("typeId") long typeId)
    {
        return success(deviceTypeService.deleteDeviceTypeTableByTypeId(typeId));
    }

}
